package com.act.web;

import org.apache.log4j.Logger;
import java.util.*;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.act.domain.Sumweek;
import com.act.dto.PagerDTO;
import com.act.dto.Response;
import com.act.service.api.ISumweekService;
import com.act.util.LoggerUtil;
import com.act.vo.PagerVo;

@RestController
@RequestMapping("/week1")
public class SumweekController {

	@Resource
	private ISumweekService sumweekService;

	private final Logger LOGGER = Logger.getLogger(SumweekController.class);

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public Response add(Sumweek sumweek) {
		try {
//			sumweekService.add(sumweek);
			return Response.success();
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
			return Response.fail();
		}
	}

	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ResponseBody
	public Response update(Sumweek sumweek) {
		try {
			System.out.println(sumweek.toString());
			sumweekService.update(sumweek);
			return Response.success();
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
			return Response.fail();
		}
	}

	@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
	@ResponseBody
	public Response delete(@PathVariable int id) {
		try {
			sumweekService.delete(id);
			return Response.success();
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
			return Response.fail();
		}
	}

	@RequestMapping(value = "/get", method = RequestMethod.POST)
	@ResponseBody
	public Response getAll(@RequestBody PagerDTO pagerDTO) {
		try {
			PagerVo<Map> amlist = sumweekService.getAllList(pagerDTO);

			return Response.success(amlist);
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
		}
		return Response.fail();
	}

	@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
	@ResponseBody
	public Response getById(@PathVariable int id) {
		try {
			Sumweek sumweek = sumweekService.getById(id);
			return Response.success(sumweek);
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
		}
		return Response.fail();
	}
	
	@RequestMapping(value = "/getByEidTime/{jobnum}/{startTime}/{endTime}", method = RequestMethod.POST)
	@ResponseBody
	public Response getByEidTime(@PathVariable String jobnum,@PathVariable String startTime,@PathVariable String endTime,@RequestBody PagerDTO pagerDTO) {
		try {
			PagerVo<Map> pagerVo = sumweekService.getByEidTime(jobnum, startTime, endTime, pagerDTO);
			return Response.success(pagerVo);
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
		}
		return Response.fail();
	}
}
